feat: add Merkl adapter#171
Open
BaptistG wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new MerklAdapter ERC4626 wrapper that forwards assets into an underlying ERC4626 vault while accruing performance (on interest) and management (time-based) fees via share dilution to a feeRecipient.
Changes:
- Introduces
MerklAdapter.solas an upgradeable ERC4626 wrapper around an underlying ERC4626 vault. - Implements fee accrual (
_accrueFee) that mints adapter shares to a fee recipient based on interest earned and elapsed time. - Adds owner-governed setters for performance fee, management fee, and fee recipient.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+187
to
+188
| underlyingVault.withdraw(assets, receiver, address(this)); | ||
| lastTotalAssets = totalAssets(); |
| // ================================= GOVERNANCE ================================= | ||
|
|
||
| /// @notice Updates the performance fee (capped at 100%). Accrues outstanding fees first. | ||
| function setPerformanceFee(uint256 _performanceFee) external onlyOwner { |
| } | ||
|
|
||
| /// @notice Updates the management fee (per-second rate). Accrues outstanding fees first. | ||
| function setManagementFee(uint256 _managementFee) external onlyOwner { |
| } | ||
|
|
||
| /// @notice Updates the recipient of both fees. Accrues outstanding fees to the old recipient first. | ||
| function setFeeRecipient(address _feeRecipient) external onlyOwner { |
Comment on lines
+136
to
+140
| function totalAssets() public view override returns (uint256) { | ||
| return | ||
| underlyingVault.convertToAssets(underlyingVault.balanceOf(address(this))) + | ||
| IERC20Upgradeable(asset()).balanceOf(address(this)); | ||
| } |
Comment on lines
+199
to
+231
| function _accrueFee() internal { | ||
| uint256 newTotalAssets = totalAssets(); | ||
| uint256 elapsed = block.timestamp - lastUpdate; | ||
|
|
||
| uint256 feeAssets; | ||
| if (newTotalAssets > lastTotalAssets && performanceFee != 0) { | ||
| uint256 interest = newTotalAssets - lastTotalAssets; | ||
| feeAssets = interest.mulDiv(performanceFee, BASE_18); | ||
| } | ||
| if (elapsed != 0 && managementFee != 0) { | ||
| feeAssets += newTotalAssets.mulDiv(managementFee * elapsed, BASE_18); | ||
| } | ||
| // Fees can never exceed the assets actually under management. | ||
| if (feeAssets > newTotalAssets) feeAssets = newTotalAssets; | ||
|
|
||
| uint256 feeShares; | ||
| if (feeAssets != 0) { | ||
| uint256 assetsAfterFees = newTotalAssets - feeAssets; | ||
| // Mirrors ERC4626 `_convertToShares` but against the post-fee asset base, so that the minted | ||
| // shares are worth `feeAssets` once they dilute the existing supply. | ||
| feeShares = feeAssets.mulDiv( | ||
| totalSupply() + 10 ** _decimalsOffset(), | ||
| assetsAfterFees + 1, | ||
| MathUpgradeable.Rounding.Down | ||
| ); | ||
| if (feeShares != 0) _mint(feeRecipient, feeShares); | ||
| } | ||
|
|
||
| lastTotalAssets = newTotalAssets; | ||
| lastUpdate = block.timestamp; | ||
|
|
||
| emit FeesAccrued(feeShares, newTotalAssets); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's NOT from VaultV2
The specific risks an auditor needs to look at